package com.lnt.mq.rabbitmq.workqueue;

import com.lnt.mq.rabbitmq.util.RabbitConstant;
import com.lnt.mq.rabbitmq.util.RabbitUtil;
import com.rabbitmq.client.*;

import java.io.IOException;

/**
 * 短信发送系统1
 * 扮演接收者行为
 */
public class SMSSendSystem2 {

    public static void main(String[] args) throws IOException {
        Connection connection = RabbitUtil.getConnection();
        final Channel channel = connection.createChannel();
        channel.queueDeclare(RabbitConstant.QUEUR_SMS, false, false, false, null);
        channel.basicQos(1);
        channel.basicConsume(RabbitConstant.QUEUR_SMS, false, new DefaultConsumer(channel){
            
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                String jsonString = new String(body);
                System.out.println("SMSSystem2--短信发送成功" + jsonString);
                channel.basicAck(envelope.getDeliveryTag(), false);
            }
        });
    }
}